﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace secuerFTP
{
    public class FileOrDirectory
    {
        private int fileOrDirectoryType;
        private String name;
        private String fullName;
        private DateTime lastWriteTime;
        private Int64 length;

        public int FileOrDirectoryType { get => fileOrDirectoryType; set => fileOrDirectoryType = value; }
        public string Name { get => name; set => name = value; }
        public string FullName { get => fullName; set => fullName = value; }
        public DateTime LastWriteTime { get => lastWriteTime; set => lastWriteTime = value; }
        public long Length { get => length; set => length = value; }
    }
    public class DataPocket
    {
        private int pocketType; //数据包类型
        private int pocketDataLength; //数据包中数据部分长度
        private int fileAndDirectoryCount; //子目录及文件个数
        private int pocketLength; //整个包的长度
        private byte[] content; //文件内容
        private List<FileOrDirectory> fileAndDirectoryList;
        
        //private FileSystemInfo[] fileAndDirectoryList; //列出的目录或请求文件列表

        public int PocketType { get => pocketType; set => pocketType = value; }
        public int PocketDataLength { get => pocketDataLength; set => pocketDataLength = value; }
        public int FileAndDirectoryCount { get => fileAndDirectoryCount; set => fileAndDirectoryCount = value; }
        public int PocketLength { get => pocketLength; set => pocketLength = value; }
        public byte[] Content { get => content; set => content = value; }
        public List<FileOrDirectory> FileAndDirectoryList { get => fileAndDirectoryList; set => fileAndDirectoryList = value; }

        //public FileSystemInfo[] FileAndDirectoryList { get => fileAndDirectoryList; set => fileAndDirectoryList = value; }

        public DataPocket()
        {
            this.PocketType = 0;
            this.PocketDataLength = 0;
            this.FileAndDirectoryCount = 0;
            this.PocketDataLength = 0;
            this.Content = new byte[0];
            this.FileAndDirectoryList = new List<FileOrDirectory>();
            //this.FileAndDirectoryList = new FileSystemInfo[0];
        }

        override
        public String ToString()
        {
            //String FileAndDirectoryListString = "";
            //foreach (FileSystemInfo FileOrDirectory in FileAndDirectoryList)
            //{
            //    FileAndDirectoryListString += FileOrDirectory.FullName;
            //    FileAndDirectoryListString += "\n";
            //}

            String FileAndDirectoryListString = "";
            for (int i = 0; i < FileAndDirectoryCount; i++)
            {
                FileAndDirectoryListString += FileAndDirectoryList[i].FullName;
                FileAndDirectoryListString += "\n";
            }
            return "PocketType : " + PocketType.ToString() + "\n"
                + "PocketDataLength : " + PocketDataLength.ToString() + "\n"
                + "PocketLength : " + PocketLength.ToString() + "\n"
                + "Context : \n" + Encoding.UTF8.GetString(Content) + "\n"
                + "FileAndDirectoryCount : " + FileAndDirectoryCount.ToString() + "\n"
                + "FileAndDirectoryList : " + "\n" + FileAndDirectoryListString;
        }
    }

}
